import { notification } from 'ant-design-vue'

/**
 * 通用通知工具
 * 提供各种类型的美观通知样式，包括成功、错误、警告、信息等
 */
export const AnyNotification = {

  /**
   * 字段验证错误通知
   */
  validationError: (fieldErrors: Record<string, string>, title = '字段验证失败') => {
    const errorList = Object.entries(fieldErrors)
      .map(([field, msg]) => `• ${msg}`)
      .join('\n')

    notification.error({
      message: `🚫 ${title}`,
      description: errorList,
      duration: 6,
      style: {
        whiteSpace: 'pre-line'
      },
      placement: 'topRight'
    })
  },

  /**
   * 参数错误通知
   */
  parameterError: (message: string) => {
    notification.error({
      message: '⚠️ 参数错误',
      description: message,
      duration: 4,
      placement: 'topRight'
    })
  },

  /**
   * 身份验证失败通知
   */
  authError: () => {
    notification.warning({
      message: '🔐 身份验证失败',
      description: '您的登录状态已过期，请重新登录后继续操作',
      duration: 5,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #faad14'
      }
    })
  },

  /**
   * 权限不足通知
   */
  permissionError: () => {
    notification.warning({
      message: '🚪 访问被拒绝',
      description: '您没有权限执行此操作，请联系管理员获取相应权限',
      duration: 5,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #fa8c16'
      }
    })
  },

  /**
   * 资源未找到通知
   */
  notFoundError: () => {
    notification.info({
      message: '🔍 资源未找到',
      description: '请求的资源不存在，请检查URL是否正确',
      duration: 4,
      placement: 'topRight'
    })
  },

  /**
   * 服务器错误通知
   */
  serverError: () => {
    notification.error({
      message: '💥 服务器错误',
      description: '服务器遇到了内部错误，请稍后重试或联系技术支持',
      duration: 6,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #ff4d4f'
      }
    })
  },

  /**
   * 网络连接失败通知
   */
  networkError: () => {
    notification.error({
      message: '🌐 网络连接失败',
      description: '无法连接到服务器，请检查您的网络连接或稍后重试',
      duration: 5,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #ff7875'
      }
    })
  },

  /**
   * 通用错误通知
   */
  generalError: (message: string, title = '请求失败') => {
    notification.error({
      message: `❌ ${title}`,
      description: message,
      duration: 4,
      placement: 'topRight'
    })
  },

  /**
   * 成功通知
   */
  success: (message: string, title = '操作成功') => {
    notification.success({
      message: `✅ ${title}`,
      description: message,
      duration: 3,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #52c41a'
      }
    })
  },

  /**
   * 信息通知
   */
  info: (message: string, title = '提示信息') => {
    notification.info({
      message: `💡 ${title}`,
      description: message,
      duration: 4,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #1890ff'
      }
    })
  },

  /**
   * 警告通知
   */
  warning: (message: string, title = '警告提示') => {
    notification.warning({
      message: `⚠️ ${title}`,
      description: message,
      duration: 5,
      placement: 'topRight',
      style: {
        borderLeft: '4px solid #faad14'
      }
    })
  }
}

export default AnyNotification